Skip to content

fix(spanner-jdbc): report active transaction isolation level - #14971

Open
Vcode2407 wants to merge 1 commit into
googleapis:mainfrom
Vcode2407:fix/spanner-jdbc-current-isolation
Open

Vcode2407 wants to merge 1 commit into
googleapis:mainfrom
Vcode2407:fix/spanner-jdbc-current-isolation

Conversation

@Vcode2407

Copy link
Copy Markdown

With a SERIALIZABLE connection default, getTransactionIsolation() reports SERIALIZABLE even after BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ. This change reads the isolation level from the active Spanner transaction and falls back to the connection default outside a transaction.

The mock-server regression test checks the default before BEGIN, REPEATABLE READ during the transaction, and the default again after ROLLBACK.

Fixes #14968

Validated with 218 tests across ConnectionStatementExecutorTest, JdbcConnectionTest, and TransactionMockServerTest.

@Vcode2407
Vcode2407 requested review from a team as code owners November 11, 2026 17:36

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the JDBC connection to correctly report the isolation level of the current transaction instead of always returning the default isolation level. It introduces a new getTransactionIsolationLevel() method to the Connection interface and implements it in ConnectionImpl. A test has been added to verify this behavior. The reviewer suggested preserving the check that the connection is not closed in ConnectionImpl.getTransactionIsolationLevel() to ensure that operations on a closed connection fail fast.

Comment on lines +934 to 936
public IsolationLevel getTransactionIsolationLevel() {
return isInTransaction() ? transactionIsolationLevel : getDefaultIsolationLevel();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To maintain consistency with other methods in ConnectionImpl and ensure that operations on a closed connection fail fast, we should preserve the check that the connection is not closed.

Suggested change
public IsolationLevel getTransactionIsolationLevel() {
return isInTransaction() ? transactionIsolationLevel : getDefaultIsolationLevel();
}
public IsolationLevel getTransactionIsolationLevel() {
ConnectionPreconditions.checkState(!isClosed(), CLOSED_ERROR_MSG);
return isInTransaction() ? transactionIsolationLevel : getDefaultIsolationLevel();
}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spanner-jdbc: getTransactionIsolation() returns the default isolation level instead of the current transaction's

1 participant